/*************************************************************************
	> File Name: test5.c
	> Author: H.M. Lau
	> Mail: hm.lau@outlook.com
	> Created Time: 2023/08/30 16:48
 ************************************************************************/

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]) {
    if (argc != 2) return 2;
    int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC);
    if (fd < 0) {
        perror("open");
        return 1;
    }
    dup2(fd, 1);
    fprintf(stdout, "%s", argv[1]);
    close(fd);
    return 0;
}
